package com.ozo.cloud.manage.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.cloud.api.manage.vo.SysDeptVO;
import com.ozo.cloud.common.base.model.BaseBatchDTO;
import com.ozo.cloud.common.base.model.ResultVO;
import com.ozo.cloud.common.log.annotation.OperateLog;
import com.ozo.cloud.manage.pojo.dto.ChangeStatusDTO;
import com.ozo.cloud.manage.pojo.dto.SysDeptQueryDTO;
import com.ozo.cloud.manage.pojo.dto.SysDeptSaveDTO;
import com.ozo.cloud.manage.service.ISysDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @since 2024-07-11
 */
@Tag(name = "部门管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/dept")
public class SysDeptController {

    private final ISysDeptService sysDeptService;

    @OperateLog(value = "添加部门", module = "部门")
    @SaCheckPermission("manage:dept:add")
    @Operation(summary = "添加部门")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid SysDeptSaveDTO saveDTO) {
        sysDeptService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "删除部门", module = "部门")
    @SaCheckPermission("manage:dept:remove")
    @Operation(summary = "删除部门")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysDeptService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑部门", module = "部门")
    @SaCheckPermission("manage:dept:edit")
    @Operation(summary = "编辑部门")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody SysDeptSaveDTO saveDTO) {
        sysDeptService.edit(saveDTO);
        return ResultVO.success();
    }

    @SaCheckPermission("manage:dept:list")
    @Operation(summary = "部门列表")
    @GetMapping("/list")
    public ResultVO<List<SysDeptVO>> list(SysDeptQueryDTO queryDTO) {
        return ResultVO.success(sysDeptService.list(queryDTO));
    }

    @OperateLog(value = "修改状态", module = "部门")
    @SaCheckPermission("manage:dept:changeStatus")
    @Operation(summary = "修改状态")
    @PutMapping("/changeStatus")
    public ResultVO<Void> changeStatus(@RequestBody @Valid ChangeStatusDTO statusDTO) {
        sysDeptService.changeStatus(statusDTO);
        return ResultVO.success();
    }

}
